package com.mxpio.erp.plm.controller;

import com.mxpio.erp.common.plm.entity.ProjectInfo;
import com.mxpio.erp.common.plm.entity.ProjectInfoComplete;
import com.mxpio.erp.common.plm.entity.ProjectInfoEnd;
import com.mxpio.erp.common.plm.entity.ProjectPauseOperation;
import com.mxpio.erp.common.plm.service.ProjectInfoEndService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "ProjectInfoEndController", description = "项目信息终止")
@RestController
@RequestMapping("/erp/plm/pro/info/end/")
public class ProjectInfoEndController {

    @Autowired
    private ProjectInfoEndService projectInfoEndService;

    @PutMapping("edit")
    @Operation(summary = "编辑信息", description = "编辑信息", method = "PUT")
    public Result<ProjectInfoEnd> edit(@RequestBody ProjectInfoEnd end) {
        projectInfoEndService.update(end);
        return Result.OK(end);
    }

    @GetMapping("list/{bizNo}")
    @Operation(summary = "根据申请单号-获取申请信息", description = "根据申请单号-获取申请信息", method = "GET")
    public Result<ProjectInfoEnd> getById(@PathVariable(name = "bizNo", required = true) String bizNo) {
        ProjectInfoEnd end = projectInfoEndService.getById(ProjectInfoEnd.class, bizNo);
        return Result.OK(end);
    }
    @GetMapping("list/all/{proCode}")
    @Operation(summary = "根据项目编码-获取申请单", description = "根据项目编码-获取申请单", method = "GET")
    public Result<List<ProjectInfoEnd>> getList(@PathVariable(name = "proCode", required = true) String proCode) {
        List<ProjectInfoEnd> list = projectInfoEndService.list(ProjectInfoEnd.class, Criteria.create().addCriterion("proCode", Operator.EQ, proCode));
        return Result.OK(list);
    }

    @GetMapping("one/{bizNo}")
    @Operation(summary = "根据项目编码-获取正在审批的申请单", description = "根据项目编码-获取正在审批的申请单", method = "GET")
    public Result<ProjectInfo> getOne(@PathVariable(name = "bizNo", required = true) String bizNo) {
        ProjectInfo end = projectInfoEndService.getOne(bizNo);
        return Result.OK(end);
    }

    @GetMapping("detail/{bizNo}")
    @Operation(summary = "根据申请单编码-获取正在审批的申请单详情内容", description = "根据申请单编码-获取正在审批的申请单详情内容", method = "GET")
    public Result<?> getDetail(@PathVariable(name = "bizNo", required = true) String bizNo) {
        return projectInfoEndService.getDetail(bizNo);
    }
}
